package com.study.stack;

public class ArrayStack {
    public int maxSize;
    public Object[] arr;
    public int top = -1;

    //
    public ArrayStack(int maxSize) {
        this.maxSize = maxSize;
        this.arr = new Object[maxSize];
    }

    //判断栈满
    public Boolean isFull() {
        return top == maxSize - 1;
    }

    //判断栈空
    public Boolean isNull() {
        return top == -1;
    }

    // 添加元素(入栈)
    public void push(Object element) {
        if (isFull()) {
            System.out.println("this stack is full");
            return;
        }
        arr[top + 1] = element;
        top++;
    }

    //出栈
    public Object pop() {
        if (isNull()) {
            System.out.println("this stack is null");
            return null;
        }
        System.out.println(arr[top]);
        Object a = arr[top];
        top--;
        return a;
    }
    public void list() {
        for (int i = top; i >= 0; i--) {
            System.out.println(arr[i]);
        }
    }

}
